//
//  CertificationCell.m
//  JiFengDaRen
//
//  Created by zhuchao on 16/7/14.
//  Copyright © 2016年 SH_iOS. All rights reserved.
//

#import "CertificationCell.h"
#import "CustomView.h"
@implementation CertificationCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self configUI];
    }
    return self;
    
}

-(void)configUI{
    
    self.nameLabel = [[UILabel alloc]init];
    self.nameLabel.font = KSystemFont(__I6Width(15));
    self.nameLabel.text = @"*证件照片";
    self.nameLabel.textColor = [UIColor blackColor];
    [self addSubview:self.nameLabel];
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).with.offset(__I6Width(15));
        make.top.equalTo(self.mas_top).with.offset(__I6Height(15));
        make.width.mas_equalTo(__I6Width(100));
        make.height.mas_equalTo(__I6Height(20));
    }];
    
    CGFloat kMaginMin  = __I6Width(15);
    CGFloat kMaginMax = ((KScreenWidth - __I6Width(108) * 3) - 2 * kMaginMin)/2;
    NSArray *titleArr = @[@"身份证正面",@"身份证反面",@"手持身份证正面"];
    for (int i = 0 ; i < 3; i ++) {
        CustomView *view = [[CustomView alloc]initWithFrame:CGRectMake(kMaginMin + i * (__I6Width(108) + kMaginMax), __I6Height(50), __I6Width(108), __I6Height(120)) image:[UIImage imageNamed:@"customView_bg"] title:titleArr[i]];
        
        view.index = 1000 + i;
        if (i < 2) {
            view.titleLabel.textAlignment = NSTextAlignmentCenter;
        }
        
        UITapGestureRecognizer *ges = [[UITapGestureRecognizer   alloc]initWithTarget:self action:@selector(actionPhto:)];
        [view addGestureRecognizer:ges];
        [self addSubview:view];
    }
    
    
    
    
    
    
    
    
    self.windowBtn = [[MiDaiBaoButton alloc]init];
    self.windowBtn.tag = 100;
    
    [self.windowBtn setTitle:@"同意" forState:UIControlStateNormal];
    [self.windowBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    self.windowBtn.titleLabel.font = KSystemFont(__I6Width(15));
    [self addSubview:self.windowBtn];
    [self.windowBtn setImage:[UIImage imageNamed:@"midaibao_normal"] forState:UIControlStateNormal];
    [self.windowBtn setImage:[UIImage imageNamed:@"midaibao_selected"] forState:UIControlStateSelected];
    [self.windowBtn addTarget:self action:@selector(agree:) forControlEvents:UIControlEventTouchUpInside];
    [self.windowBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).with.offset(__I6Width(15));
        make.top.equalTo(self.mas_top).with.offset(__I6Height(160));
        make.width.mas_equalTo(__I6Width(60));
        make.height.mas_equalTo(__I6Height(36));
    }];
    
    self.proBtn = [[UIButton alloc]init];
    self.proBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    [self.proBtn setTitle:@"《收款服务协议》" forState:UIControlStateNormal];
    self.proBtn.titleLabel.font = KSystemFont(__I6Width(12));
    [self.proBtn setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    [self addSubview:self.proBtn];
    [self.proBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.windowBtn.mas_right).with.offset(__I6Width(0));
        make.top.equalTo(self.mas_top).with.offset(__I6Height(160));
        make.width.mas_equalTo(__I6Height(160));
        make.height.mas_equalTo(__I6Height(36));
    }];
    
    self.certification = [[UIButton alloc]init];
    [self.certification setBackgroundImage:[UIImage imageNamed:@"btn_bg"] forState:UIControlStateNormal];
    self.certification.titleLabel.font = KSystemFont(16);
    [self.certification setTitleColor:KSHTEXTCOLOR forState:UIControlStateNormal];
    [self.certification setTitle:@"提交审核" forState:UIControlStateNormal];
    [self addSubview:self.certification];
    [self.certification addTarget:self action:@selector(certification:) forControlEvents:UIControlEventTouchUpInside];
    [self.certification mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self);
        make.top.equalTo(self.proBtn.mas_bottom).with.offset(__I6Height(25));
    }];
    
    
    
    
}
-(void)agree:(UIButton * )btn{
    btn.selected = !btn.selected;
    [Tool  setBool:btn.selected forKey:@"同意协议"];
}
#pragma mark --- 提交审核
-(void)certification:(UIButton *)btn{
    
    if ([_delegate respondsToSelector:@selector(jmForCertification)]) {
        [_delegate jmForCertification];
    }
    
    
}
#pragma  mark-- 上传照片
-(void)actionPhto:(UIGestureRecognizer *)ges{
    
    if ([_delegate respondsToSelector:@selector(updatePhoto:customView:)]) {
        [_delegate updatePhoto:self customView:(CustomView *)ges.view];
    }
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
